package edu.pku.sei.transformation.editor.views.figures;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.graphics.Color;

public class BendCornerBorder extends LineBorder {
	private static final int a = 5;

	public BendCornerBorder() {
		super();
	}

	public BendCornerBorder(Color color, int width, int style) {
		super(color, width, style);
	}

	public BendCornerBorder(Color color, int width) {
		super(color, width);
	}

	public BendCornerBorder(Color color) {
		super(color);
	}

	public BendCornerBorder(int width) {
		super(width);
	}

	@Override
	public void paint(IFigure figure, Graphics graphics, Insets insets) {
		tempRect.setBounds(getPaintRectangle(figure, insets));
		if (getWidth() % 2 != 0) {
			tempRect.width--;
			tempRect.height--;
		}
		tempRect.shrink(getWidth() / 2, getWidth() / 2);
		graphics.setLineWidth(getWidth());
		graphics.setLineStyle(getStyle());
		if (getColor() != null)
			graphics.setForegroundColor(getColor());
		graphics.drawLine(tempRect.x, tempRect.y, tempRect.x + tempRect.width,
				tempRect.y);
		graphics.drawLine(tempRect.x + tempRect.width, tempRect.y, tempRect.x
				+ tempRect.width, tempRect.y + tempRect.height - a);
		graphics.drawLine(tempRect.x, tempRect.y, tempRect.x, tempRect.y
				+ tempRect.height);
		graphics.drawLine(tempRect.x, tempRect.y + tempRect.height, tempRect.x
				+ tempRect.width - a, tempRect.y + tempRect.height);
		graphics.drawLine(tempRect.x + tempRect.width - a, tempRect.y
				+ tempRect.height, tempRect.x + tempRect.width, tempRect.y
				+ tempRect.height - a);

		// graphics.drawRectangle(tempRect);
	}
}
